const webpack = require('webpack')
const path = require('path');
const appDirectory = path.resolve(__dirname, '../')
const CopyPlugin = require('copy-webpack-plugin')


const babelLoaderConfiguration = {
  test: /(\.jsx|\.js)$/,
  include: [
    path.resolve(appDirectory, 'src'),
    path.resolve(appDirectory, 'index.web.js'),
  ],
  use: {
    loader: 'babel-loader',
    options: {
      cacheDirectory: false,
      presets: ["@babel/preset-env", "@babel/preset-react", "module:metro-react-native-babel-preset"],
      plugins: [
        ["@babel/plugin-proposal-decorators", { "legacy": true }],
        [require("@babel/plugin-proposal-class-properties"), { "loose": false }],
      ]
    },
  },

}
const imageLoaderConfiguration = {
  test: /\.(gif|jpe?g|png|svg)$/,
  use: {
    loader: 'url-loader',
    options: {
      limit:1,
      name: '/images/[name].[ext]',
    },
  },
}

const htmlLoaderConfiguration = {
  test: /\.html$/,
  use: {
    loader: 'html-loader'
  }
}

const cssLoaderConfiguration = {
  test: /\.css|\.less$/,
  use: ['style-loader',
    'css-loader'],
}

module.exports = {
  mode: 'development',
  // mode: 'production',
  entry: path.resolve(appDirectory, 'index.web.js'),
  // devtool: 'eval-source-map',
  devtool: 'false',
  output: {
    filename: '[name].bundle.js',
    path: path.resolve(appDirectory, './web/public'),
  },
  devServer: {
    contentBase: path.join(__dirname, 'public'),
    historyApiFallback: true,
    inline: true,
    hot: true,
    progress: true,
    proxy:{
      '/api/*':{
        // target:'https://www.flydeer.app',
        target:'https://www.winwinin.app',
        changeOrigin:true,
      }
    }

  },

  module: {
    rules: [
      babelLoaderConfiguration,
      cssLoaderConfiguration,
      imageLoaderConfiguration,
      htmlLoaderConfiguration,
    ]
  },
  plugins: [
    // new webpack.HotModuleReplacementPlugin(),

    new CopyPlugin({
      patterns:[
        {
          from:path.resolve(appDirectory,'src/images') ,
          to:path.resolve(appDirectory, './web/public/images')
        }
      ]
    })
  ],
  resolve: {
    extensions: ['.web.js', '.js'],
    alias: {
      'react-native$': 'react-native-web',
      'react-native-linear-gradient': 'react-native-web-linear-gradient'
    },
  },
  performance: {
    hints: false
  }

}
